package com.nan.leetcode.剑指offer第二版.二维数组元素查找;

public class Main {
    public boolean findNumberIn2DArray1(int[][] matrix, int target) {
        for(int i=0;i< matrix.length;i++) {//控制行数
            for (int j = 0; j < matrix[0].length; j++) {//看一行中有多少列
                if (matrix[i][j] == target) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        if(matrix.length==0){
            return false;
        }
       int x=matrix.length-1;
       int y=0;
       while (y<matrix[0].length && x >=0){
           if(target>matrix[x][y]){
               y++;
           }else if(target<matrix[x][y]){
               x--;
           }else {
               return true;
           }
       }
       return false;
    }
}
